package com.rg.servlet;

import com.rg.model.GoodsType;
import com.rg.service.GoodsTypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/GoodsTypeServlet")
public class GoodsTypeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        GoodsTypeService goodsTypeService=new GoodsTypeService();
        List<GoodsType> typelist= null;
        try {
            typelist = goodsTypeService.getAllType();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        HttpSession session=req.getSession();
        session.setAttribute("goodsType",typelist);
        // req.setAttribute("goodsType",typelist);
        req.getRequestDispatcher("GoodsRecommandServlet").forward(req,resp);
    }
}
